
/**
 * @param {*} b
 * @returns {boolean|undefined} true or false when the specified argument is either of those values, otherwise undefined
 */
export function castBool(b) {
    return b === true || b === false ? !!b : undefined;
}

/**
 * @param {*} x
 * @param {number} d
 * @returns {number}
 */
export function coalesceNum(x, d) {
    return isNaN(x ?? undefined) ? d : +x;
}

/**
 * @param {*} x
 * @returns {number}
 */
export function convertToNum(x) {
    if (x === null || typeof x === "string" && x.trim() === "") {
        return NaN;
    }
    return +x;
}
